#ifndef __GSM_H__
#define __GSM_H__

#include "vbb_Header.h"
#include "fw/vbb_Utils.h"

void vbb_GSM_Init(void);
void vbb_GSM_Flush(void);
bool vbb_GSM_PostData(char * ResponseBuffer, char * DataBuffer, unsigned int DataLength, unsigned int * ReceiveLength, const char * URL);

char * vbb_GSM_GetIMEI(void);
char * vbb_GSM_GetIdentity(void);

bool GSM_CheckInbox(void);
bool vbb_GSM_SendSMS(const char * Number, const char * MessageBody);

void vbb_GSM_StartDownloadFirmware(unsigned int Version, bool OverrideCurDownload);
void vbb_GSM_CancelDownloadFirmware(void);
bool vbb_GSM_ContinueDownloadFirmware(void);

char * GSM_QueryCUSD(const char * CUSD_Query);
void vbb_GSM_QueryCUSD(const char * CUSD_Query);
void vbb_GSM_Update(void);
bool vbb_GSM_MakeMuteCall(const char * Number);

void GSM_PutCommand(const char * Command);
bool GSM_CommandFinished(void);
char GSM_WaitForAnswerUpdate(const char * Value1, const char * Value2, const char * Value3, const char * Value4, unsigned int TimeOut);
char GSM_Command(const char * Command, const char * Value1, const char * Value2, const char * Value3, const char * Value4, unsigned int TimeOut);

bool GSM_OpenGPRS(void);
char GSM_WriteByte(char Byte);

void GSM_SwitchOff(void);
void GSM_SwitchOn(void);
bool GSM_IsOn(void);
bool GSM_IsOff(void);
bool GSM_Ready(void);
void GSM_Reboot(void);

#define CONNECTION_TIMEOUT 120

#define TCP_CONNECTION_ALLOCATED        2
#define TCP_CONNECTION_CONNECTING       3
#define TCP_CONNECTION_UP               4
#define TCP_CONNECTION_CLOSING          5
#define TCP_CONNECTION_DOWN             6

#define GSM_BUFFER_SIZE 4096

enum {
    GSM_BEFORE_REBOOT = 0,
    GSM_TURNED_OFF,
    GSM_TURNED_ON,
    GSM_SETUP,
    GSM_READY,
};

#endif

